<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Outcomes Table</title>
</head>

<body>

<h2>Outcomes Table</h2>

<p>A typical use case when outcomes are collected in a tabular format is to verify them all at once.  To this end, JBehave
provides the <a href="javadoc/core/org/jbehave/core/model/OutcomesTable.html">OutcomesTable</a>:</p>

<script type="syntaxhighlighter" class="brush: java">
<![CDATA[
    @Then("the values returned are: $table")
    public void theValuesReturnedAre(ExamplesTable table) {
        Map<String,String> actual = actualValues(); // obtained from another step invocation
        OutcomesTable outcomes = new OutcomesTable();
        Map<String,String> expected = table.getRow(0); // assuming all values are contained in a single row
        for ( String key : expected.keySet() ){
            outcomes.addOutcome(key, actual.get(key), Matchers.equalTo(expected.get(key)));            
        }
        outcomes.verify();
    }
]]>
</script>

<p>The user adds each outcome using a <a href="http://code.google.com/p/hamcrest/">Hamcrest</a> Matcher:</p>
<script type="syntaxhighlighter" class="brush: java">
<![CDATA[
    public <T> void addOutcome(String description, T value, Matcher<T> matcher);
]]>
</script>

<span class="followup">The Matcher interface is contained in the <b>hamcrest-core</b> module.  A collection of Matchers
is contained in the <b>hamcrest-library</b>.  You may choose to upgrade just the library module or provide your own custom implementations
of Matcher. 
</span>

<p>Upon verification, the outcome matching is done and if any
outcome verification fails an exception is thrown and the step execution fails and 
the entire outcomes table (including all verified outcomes) is reported to the 
<a href="javadoc/core/org/jbehave/core/reporters/StoryReporter.html">StoryReporter</a>.
The TXT format would look like:</p>

<pre class="brush: text">
|Description|Value|Matcher|Verified|
|Value1|Value1|"Value1"|Yes|
|Value2|Value2|"ValueX"|No|
</pre>

<p>The HTML format would use colour-coding for failures.</p>

<h2>Using different Locales</h2>

<p>The OutcomesTable is localisable, via the injection of the appropriate <a
    href="javadoc/core/org/jbehave/core/i18n/LocalizedKeywords.html">LocalizedKeywords</a>.</p>

<script type="syntaxhighlighter" class="brush: java">
<![CDATA[
     new OutcomesTable(new LocalizedKeywords(new Locale(...)));
]]>
</script>

<p>The TXT format would look like, in FR locale:</p>

<pre class="brush: text">
|Déscription|Valeur|Matcher|Vérifié|
|Value1|Value1|"Value1"|Oui|
|Value2|Value2|"ValueX"|Non|
</pre>

<div class="clear">
<hr />
</div>

</body>
</html>